package com.vf.admin.client.dao;

import com.vf.admin.common.db.BaseDao;
import com.vf.admin.common.splitpage.SplitPageBean;
import com.vf.admin.miaodong.entity.AppDashan;
import com.vf.admin.miaodong.entity.AppDynamic;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;
import java.util.List;

import static com.vf.admin.utils.StringEx.isNull;

/**
 * 搭讪
 */
@Repository
public class AppDashanDao extends BaseDao<AppDashan> {

    /**
     * 查询指定用户的搭讪记录
     */
    public AppDashan getDashan(Integer userid,Integer xid,String uuid) {
        if(xid==null || xid<=0){
            return null;
        }
        ArrayList<Object> paramList = new ArrayList<Object>();
        StringBuilder sbStr = new StringBuilder("select * from app_dashan where huiying = 2  and userid = ? and fsuserid = ? and uuid = ? limit 1 ");
        paramList.add(userid);
        paramList.add(xid);
        paramList.add(uuid);
        String sql = sbStr.toString();
        return this.queryObj(sql, paramList, AppDashan.class);
    }

    /**
     * 添加/修改
     */
    public void save(AppDashan pojo) {
        if (pojo!=null && pojo.getId() != null && pojo.getId() > 0) {
            this.update(pojo);
        } else {
            pojo.setId(this.add(pojo));
        }
    }

    //更新状态
    public void updateHuiying(Integer xid,Integer userId) {
        if (xid==null || xid <= 0) {
            return;
        }
        String sql = "update app_dashan set huiying = 1 where userid = ? and fsuserid =? ";
        List<Object> paramList = new ArrayList<Object>();
        paramList.add(xid);
        paramList.add(userId);
        this.update(sql, paramList);
    }


}
